package net.love5z.web.controller;

import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class LoveDaysController {

    @RequestMapping(value = { "/we", "/we/" }, method = RequestMethod.GET)
    public String index(ModelMap map, HttpServletRequest request, HttpServletResponse response) {

        map.addAttribute("loveDays", getLoveDays());
        return "love_days/index.vm";
    }

    private static long getLoveDays() {
        long days = 0;

        Calendar loveCalendar = Calendar.getInstance(TimeZone.getTimeZone("GMT+8"), Locale.CHINA);

        loveCalendar.set(2010, 9, 4, 22, 01, 56);
        Date beginDate = loveCalendar.getTime();

        //        loveCalendar.set(2012, 1, 4, 22, 00, 00);
        //        Date endDate = loveCalendar.getTime();
        Date endDate = new Date();

        days = (endDate.getTime() - beginDate.getTime()) / (24 * 60 * 60 * 1000);

        return days;
    }

}
